﻿using System.Collections.Generic;

namespace ProblemsSet
{
    public class Problem_35 : BaseProblem
    {
        public override object GetResult()
        {
            var tmp = new HashSet<long>(MathLogic.GetPrimeList(1000000, true));
            var exists = new HashSet<long>();
            foreach (var l in tmp)
            {
                var q = MathLogic.GetDigitSet(l);
                if (q.Contains(0)) continue;
                if (q.Contains(2) && q.Count > 1) continue;
                if (q.Contains(4)) continue;
                if (q.Contains(6)) continue;
                if (q.Contains(8)) continue;
                if (q.Contains(5) && q.Count > 1) continue;
                if (exists.Contains(l)) continue;
                var circ = MathLogic.GetCircular(l);
                var ex = true;
                foreach (var l1 in circ)
                {
                    if (tmp.Contains(l1)) continue;
                    ex = false;
                    break;
                }
                if (!ex) continue;
                foreach (var l1 in circ)
                {
                    if (!exists.Contains(l1))
                    {
                        exists.Add(l1);
                    }
                }

            }
            return exists.Count;
        }

        public override string Problem
        {
            get
            {
                return @"The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 55;
            }
        }

    }
}
